//
//  PopoverPresentationController.swift
//  CXCWeibo
//
//  Created by cxc on 15/6/27.
//  Copyright © 2015年 china. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    var presentFrame = CGRectZero
    
    lazy var dummyView : UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        return view
    }()
    
    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
        
        prepareDummyView()
    }
    
    func close() {
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
    private func prepareDummyView(){
        let tap = UITapGestureRecognizer(target: self, action: "close")
        dummyView.addGestureRecognizer(tap)
    }
    
    /**容器view将要布局子控件*/
    override func containerViewWillLayoutSubviews() {
        dummyView.frame = (containerView?.bounds)!
        containerView?.insertSubview(dummyView, atIndex: 0)
        
        presentedView()?.frame = presentFrame
    }
}
